var module;
var Main = function() {
	if(!isH5 && window.plus) {
		$('.mui-bar').remove();
		//$('#btn-affirm').hide();
		var wvs = plus.webview.getWebviewById('huifu-page')
		if(wvs) {
			wvs.evalJS("removeBackBtn();");
		}
	}
	mui.init({
		swipeBack: false //启用右滑关闭功能
	});
	this.init();
	this.even();
};
Main.prototype = {
	init: function() {
		var msg = Util.requestURL('msg');
		module = Util.requestURL('module');
		var title;
		switch(module) {
			case 'registerAccount':
				title = "开通第三方";
				break;
			case 'recharge':
				title = "充值";
				break;
			case 'withdraw':
				title = "提现";
				break;
			case 'bank':
				title = "绑定银行卡";
				break;
			default:
				break;
		}
		$('.mui-title').text(title);
		$('#message').text(msg);
	},
	even: function() {
		function closeWebview() {
			//关闭页面
			mui.plusReady(function() {
				// 获取所有Webview窗口
				var wvs = plus.webview.all();
				for(var i = 0; i < wvs.length; i++) {
					var webview = wvs[i].id;
					//console.log("webview" + i + ": " + wvs[i].id);
					if(wvs[i].id == 'huifu-1' || wvs[i].id == 'huifu-page') {
						plus.webview.close(wvs[i]);
					}
					if(wvs[i].id == 'recharge' || wvs[i].id == 'withdraw' ||
						wvs[i].id == 'bidPlanDetail' || wvs[i].id == 'bidPlanConfirm' || wvs[i].id == 'bidSaleDetail' || wvs[i].id == 'bidSaleConfirm' || webview == 'bankList' || webview == 'registerAccount') {
						plus.webview.close(wvs[i]);
						var userView = plus.webview.getWebviewById('user');
						if(userView) {
							userView.evalJS('Main.loadData()');	
						}
					}
				}
			});
		}
		$('#btn-close').on('tap', function() {
			if(!isH5 && window.plus) {
				closeWebview();
			} else {
				mui.openWindow("user.html", 'user');
			}
		})
		$('#btn-affirm').on('tap', function() {
			var backUrl;
			switch(module) {
				case 'registerAccount': //开户
					/*backUrl = "userAccount.html";
					break;*/
				case 'recharge': //充值
				case 'withdraw': //提现
					/*backUrl = "user.html";*/
					/*break;*/
				case 'bank': //绑定银行卡
					/*backUrl = "bankList.html";*/
				case 'biding': //定期投标	
				case 'buybidplan': //计划投标	
					backUrl = "user.html";
					break;
				default:
					backUrl = "user.html";
					break;
			}
			if(!isH5 && window.plus) {
				closeWebview();
			} else {
				mui.openWindow(backUrl, 'user');
			}
		})
	}
};